/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/02
*/
#include "LuaText.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (Text::ToText(m_cobj))

void* LuaText::GetInterface(void* data)
{
    if (!data) return 0;
    LuaText* text = new LuaText((Text*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaText] new LuaText : %d, %d", text, data);
#endif
    return text;
}

void LuaText::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaText] delete LuaText : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaText::LuaText(Text* text) : LuaLabel(text)
{}

LuaText::~LuaText()
{}

//----------------------------------------//

int LuaText::GetFixedSize(LuaState *L)
{
    Size sz = CObjPtr->GetFixedSize();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &sz);
    obj.Push(L);
    return 1;
}

//----------------------------------------//

void LuaText::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "Text", "Label");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaText::GetInterface);

    obj.RegisterObjectFunctor("GetFixedSize", &LuaText::GetFixedSize);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif